$(function () {
  const layer = layui.layer


  document.querySelector('form').addEventListener('submit', async (e) => {
    e.preventDefault()
    const username = document.querySelector('#username').value.trim()
    const password = document.querySelector('#password').value.trim()
    if (username.length <= 0 || password.length <= 0) {
      return alert('输入内容不可为空')
    }
    const url = 'http://124.223.14.236:3001/api/user/login'
    const dataObj = { username, password }

    const { data } = await axios.post(url, dataObj)
    console.log(data);
    if (!data.success) {
      return layer.msg(data.msg)
    } else {
      // alert('登录成功!')
      console.log(data.data.token);
      localStorage.setItem('token', data.data.token)
      // location.href = ''
    }



  })
})